package com.ws.q1.mapper;

import com.ws.q1.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface HouTaiUserMapper {
    @Insert("INSERT INTO qtyonghu(name, pass, phone, tou) VALUES (#{name}, #{pass}, #{phone}, #{tou})")
    int add(@Param("name") String name, @Param("pass") String pass, @Param("phone") String phone, @Param("tou") String tou);

    @Select("SELECT * FROM qtyonghu")
    List<User> getAllUsers();

    @Delete("DELETE FROM qtyonghu WHERE id = #{id}")
    void deleteById(@Param("id") Integer id);

    @Update("UPDATE qtyonghu SET name = #{user.name}, pass = #{user.pass}, phone = #{user.phone}, tou = #{user.tou} WHERE id = #{id}")
    void update(@Param("id") Integer id, @Param("user") User user);

    @Select("SELECT * FROM qtyonghu WHERE id = #{id}")
    User huixian(@Param("id") Integer id);

    @Select("SELECT COUNT(*) FROM qtyonghu WHERE name = #{name}")
    int isUsernameExists(@Param("name") String name);

    @Select("SELECT * FROM qtyonghu WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<User> getUsersByName(@Param("name") String name);

    @Select("SELECT * FROM qtyonghu")
    List<User> list();
}
